#include<unistd.h>
#include<fcntl.h>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void replace_is_with_are(char *str)
{
    char *pos = str;
    while ((pos = strstr(pos, "is")) != NULL)
    {
        pos[0] = 'a';
        pos[1] = 'r';
        pos[2] = 'e';
        pos += 3;  
    }
}

int main()
{
    const char *filename = "word.txt";

    int fd = open(filename, O_RDONLY);
    if(fd == -1)
    {
        perror("文件打开失败");
        return -1;
    }

    char buff[1024] = {0};
    int ret = read(fd, buff, sizeof(buff)-1);
    buff[ret] = '\0';

    close(fd);
    open(filename, O_WRONLY);

    replace_is_with_are(buff);
    
    write(fd, buff, strlen(buff));

    close(fd);
    return 0;
}